<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  
		xmlns:h="http://java.sun.com/jsf/html"  
		xmlns:f="http://java.sun.com/jsf/core"
		xmlns:ui="http://java.sun.com/jsf/facelets"
		xmlns:c="http://java.sun.com/jsp/jstl/core"
        xmlns:a4j="http://richfaces.org/a4j"
        xmlns:rich="http://richfaces.org/rich">  
    
    <ui:composition template="#{helperNavigation.getPathTemplate('administration')}">
        <ui:define name="pageTitle">Stocks critiques</ui:define>
        <ui:define name="mainTitle">Stocks critiques</ui:define>
        <ui:define name="mainContent">
            <div class="center">
                <h:form id="formCriticalStocks">
                    <c:if test="#{bookManager.loadBookUnderThreshold() == null}">
                        <h1>Aucun article n'a de stock critique.</h1>
                    </c:if>
                    <c:if test="#{bookManager.loadBookUnderThreshold() != null}">
                        <rich:dataTable value="#{bookManager.loadBookUnderThreshold()}" var="book" rows="10" rowClasses="odd-row, even-row" style="width: 100%;">
                            <f:facet name="header">
                                <rich:columnGroup>
                                    <rich:column>
                                        <h:outputText value="Titre" />
                                    </rich:column>
                                    <rich:column>
                                        <h:outputText value="Stock" />
                                    </rich:column>
                                    <rich:column>
                                        <h:outputText value="Seuil" />
                                    </rich:column>
                                    <rich:column>
                                        <h:outputText value="Modifier" />
                                    </rich:column>
                                </rich:columnGroup>
                            </f:facet>

                            <rich:column>
                                <h:outputText value="#{book.title}" />
                            </rich:column>
                            <rich:column>
                                <h:inputText value="#{book.stock}" styleClass="validate[required]" id="inputUpdateStock" class="inputUpdateStock" />
                            </rich:column>
                            <rich:column>
                                <h:outputText value="#{book.threshold}" />
                            </rich:column>
                            <rich:column>
                                <h:commandButton id="btnUpdateStock" value="Modifier" action="#{bookManager.updateStock(book)}" styleClass="btn btn-primary" />
                            </rich:column>
                        </rich:dataTable>
                    </c:if>
                </h:form>
                <script type="text/javascript">
                    $j('.inputUpdateStock').keypress(function(e){
                        var element = document.getElementById(e.target.id);
                        var idToClick = replaceString(element.id, "inputUpdateStock", "btnUpdateStock")

                        if(e.keyCode == 13){
                            document.getElementById(idToClick).click();
                        }
                    });
                </script>
            </div>
        </ui:define>
    </ui:composition>
</html>

